package com.hxd.tabactivityfragment.ui.fragment.MineOfFragment

import com.hxd.tabactivityfragment.R
import com.hxd.tabactivityfragment.bean.IMPDataInfo.IMPSucharDataInfoBean
import com.hxd.tabactivityfragment.bean.IMPDataInfo.Manufactor.ManufactorDesc
import com.hxd.tabactivityfragment.bean.IMPDataInfo.Manufactor.ManufacturerDataInfo
import com.hxd.tabactivityfragment.common.MyFragment
import com.hxd.tabactivityfragment.util.*
import com.kymjs.rxvolley.RxVolley
import com.kymjs.rxvolley.client.HttpCallback
import com.kymjs.rxvolley.client.HttpParams
import com.vondear.rxtool.RxSPTool
import kotlinx.android.synthetic.main.fragment_find_manufacturer_info.*
import kotlinx.android.synthetic.main.item_search_info.*

/**
 *  项目名：    FoodOrigins
 *  包名：      com.hxd.tabactivityfragment.ui.fragment
 *  文件名:     ManufacturerInfoFragment
 *  创建者:     HXD
 *  创建时间:   2019/3/24 15:43
 *  描述:       厂商数据界面
 */

class ManufacturerInfoFragment:MyFragment() {
    override fun getLayoutId(): Int {
        return R.layout.fragment_find_manufacturer_info
    }

    override fun getTitleBarId(): Int {
        return 0
    }

    //设置单例静态方法
    companion object {
        fun newInstance(): ManufacturerInfoFragment {
            return ManufacturerInfoFragment()
        }
    }

    override fun initView() {
        //配置轮播图
        sib_simple_usage_mi.setSource(BannerDataUtil.getDatas())
            .setOnItemClickL { position -> myToast("position--->$position") }
            .setIsOnePageLoop(false).startScroll()
    }

    override fun initData() {
        var searchData = RxSPTool.getString(context, "IMPSucharDataInfoBean")
        var bean = GsonToBean.JsonToBean<IMPSucharDataInfoBean>(searchData)
        var creator = bean.data.creator
        var params = HttpParams()
        params.putJsonParams(GsonToBean.QueryToJson(creator))
        RxVolley.jsonPost(URLProviderUtils.getIMPSearchUrl(),params, object : HttpCallback() {
            override fun onSuccess(result: String?) {
                var data = GsonToBean.JsonToBean<ManufacturerDataInfo>(result).data
                ThreadUtil.runOnMainThread(Runnable {
                    tv_MSPID.text = data.msp_id
                    var info = GsonToBean.JsonToBean<ManufactorDesc>(data.desc)
//                            L.i("info :: $info --- ${data.msp_id}")
                    tv_name.text = info.name
                    tv_time.text = info.time
                    tv_area.text = info.area
                    tv_person.text = info.representative
                    tv_type.text = info.enterprise_type
                    tv_manage_scope.text = info.manage_scope
                    tv_register.text = info.registration_authority
                })

            }

            override fun onFailure(errorNo: Int, strMsg: String?) {
                L.i("FindFragment : $strMsg")
            }
        })
    }
}